/**
    Copyright (C) 2011  Alexander Vollmer

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.jefb.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.jefb.util.JefbUtils;

@Entity(name="link")
@Table(name="CV_LINK")
public class LinkEntity extends BasicEntity implements Serializable{

	private static final long serialVersionUID = 1L;

	private String filename;
	private String relativePath;
	private boolean file;
	
	public LinkEntity() {}

	@Column(name="FILENAME", nullable=false)
	public String getFilename() {
		return filename;
	}
	
	@Column(name="RELATIVE_PATH", nullable=false)
	public String getRelativePath() {
		return relativePath;
	}
	
	@Column(name="ISFILE", nullable=false)
	public boolean getFile() {
		return file;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public void setFile(boolean file) {
		this.file = file;
	}
	
	public void setRelativePath(String relativePath) {
		this.relativePath = relativePath;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((filename == null) ? 0 : filename.hashCode());
		result = prime * result
				+ ((relativePath == null) ? 0 : relativePath.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		LinkEntity other = (LinkEntity) obj;
		if (filename == null) {
			if (other.filename != null)
				return false;
		} else if (!filename.equals(other.filename))
			return false;
		if (relativePath == null) {
			if (other.relativePath != null)
				return false;
		} else if (!relativePath.equals(other.relativePath))
			return false;
		return true;
	}
	
	@Transient
	public String getRelativeFile(){
		//TODO handle it for windows
		if(JefbUtils.FILE_SEPARATOR.equals(relativePath)){
			return JefbUtils.FILE_SEPARATOR+filename;
		}else{
			return relativePath+JefbUtils.FILE_SEPARATOR+filename;
		}
	}

		
}
